<?php

namespace App\Kuafu\WaiMai\Command;

use App\Kuafu\WaiMai\Channel\ElmWaiMai;
use App\Kuafu\WaiMai\Channel\MtWaiMai;
use App\Kuafu\WaiMai\Enum\WaiMaiDBEnum;
use App\Kuafu\WaiMai\Model\WaiMaiOrderModel;
use App\Kuafu\WaiMai\Model\WaiMaiShopMappingModel;
use App\Kuafu\WaiMai\Service\BaseWaiMaiOrderService;
use App\Kuafu\WaiMai\Service\ElmWaiMaiOrderService;
use Illuminate\Console\Command;

class WaiMaiOrderShow extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'waimai:order-show {sourceType}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '外卖订单-订单情况展示';

    /**
     * Create a new command instance.
     *
     * @return void//
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command
     *
     * @return int
     */
    public function handle()
    {
        $sourceType = $this->argument('sourceType');
        if (!$sourceType) {
            dd('sourceType必传');
        }

        $arr = [];

        for ($i = 0; $i < 100; $i++) {
            $order = WaiMaiOrderModel::suffix($i)->where('sourceType', $sourceType)->orderByDesc('createdAt')->value('createdAt');

            if ($order) {
                $arr[] = [
                    'i' => $i,
                    'createdAt' => $order->toDateTimeString(),
                ];
            } else {
                $arr[] = [
                    'i' => $i,
                    'createdAt' => '',
                ];
            }
        }

        $this->warn("======每张表里最新的外卖订单======");
        $this->warn("sourceType:{$sourceType}");
        collect($arr)->sortByDesc('createdAt')->each(function ($item) {
            $this->info("i:{$item['i']} createdAt:{$item['createdAt']}");
        });
    }
}
